package com.rightsidetech.http.controller.agentAdmin.store;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.DelReq;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.ModifyName;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.ModifyLog;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.SysUpdateStatusReq;
import com.rightsidetech.system.dtos.request.store.SysStoreLoginInfoAddReq;
import com.rightsidetech.system.dtos.request.store.SysStoreLoginInfoReq;
import com.rightsidetech.system.dtos.request.store.SysStoreLoginInfoUpdateReq;
import com.rightsidetech.system.dtos.response.store.SysStoreLoginInfoResp;
import com.rightsidetech.system.service.SysStoreLoginInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: yhr
 * @Date: 2021-11-04 09:20
 */
@Slf4j
@RestController
@RequestMapping("/agentAdmin/store_login_info")
@ShenyuSpringMvcClient(path = "/agentAdmin/store_login_info/**")
@Api(tags = "门店帐号相关")
public class StoreLoginInfoController extends BaseController {
    @Resource
    private SysStoreLoginInfoService sysStoreLoginInfoService;

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/page")
    @ApiOperation("门店帐号列表")
    public ResponseData<PageInfo<SysStoreLoginInfoResp>> page(SysStoreLoginInfoReq req){
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreLoginInfoService.page(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @ApiOperation("添加门店帐号")
    @PostMapping("/saveStoreInfo")
    @ModifyLog(serviceClass = SysStoreLoginInfoService.class,modifyType = ModifyName.SAVE)
    public ResponseData saveStoreInfo(@RequestBody SysStoreLoginInfoAddReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreLoginInfoService.saveStoreLoginInfo(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @ApiOperation("编辑帐号")
    @PostMapping("/updateAgentInfo")
    @ModifyLog(serviceClass = SysStoreLoginInfoService.class)
    public ResponseData updateStoreLoginInfo(@RequestBody SysStoreLoginInfoUpdateReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreLoginInfoService.updateStoreLoginInfo(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @ApiOperation("删除帐号")
    @PostMapping("/del")
    @ModifyLog(serviceClass = SysStoreLoginInfoService.class)
    public ResponseData delStoreInfo(@RequestBody DelReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreLoginInfoService.del(req,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @ApiOperation("编辑帐号状态")
    @PostMapping("/updateStoreStatus")
    @ModifyLog(serviceClass = SysStoreLoginInfoService.class)
    public ResponseData updateStoreStatus(@RequestBody SysUpdateStatusReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreLoginInfoService.updateStatus(req,loginInfoId);
    }

    @Log
    @Token
    @ApiOperation("门店姓名下拉")
    @GetMapping("/selectList")
    public ResponseData selectList() throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysStoreLoginInfoService.selectList(loginInfoId);
    }
}
